$(function (){

    $("#moduleType").val( $("#module").val() )
    $("#competitionType").val($("#competitionTypes").val())

    $(".addListB p").click(function (){
        let str = '';
        str = `
            <div class="parseInset">
                <div class="taskName col-sm-6" style="padding-left: 0">
                  <input name="topicName" class="form-control" type="text" placeholder="请输入细则名称">
                </div>
                <div class="taskScore col-sm-6" style="padding-left: 0;padding-right: 0">
                  <input name="score" class="form-control" type="text" placeholder="请输入分值">
                </div>
              <div class="taskDesc col-sm-12" style="padding-left: 0;padding-right: 0">
                <textarea name="description" class="form-control" type="text" placeholder="请输入具体细则"></textarea>
              </div>
                <div class="remove">删除</div>
            </div>
        `;

        $("#addParams").append(str);
    })

    $("body").on('click','.remove',function (){
        $(this).parent('.parseInset').remove();
    })

    $("#btn").click(function (){
        save();
    })

    function save() {

        let disposition = [] , maxScore = 0;

        $("#addParams").find(".parseInset").each(function (index,val){
            maxScore += parseFloat( $(val).find('.taskScore').find('input').val() );
            disposition.push({
                contentName: $(val).find('.taskName').find('input').val(),
                contentScore: $(val).find('.taskScore').find('input').val(),
                detailContent: $(val).find('.taskDesc').find('textarea').val(),
                moduleContentId: $("#id").val()
            })
        })

        let response = {
            id:$('#id').val(),
            createrId: sessionStorage.getItem('refereeId'),
            moduleName: $('#moduleName').val(),
            totalScore: maxScore,
            jzJinzhuanModuleContent:disposition,
        }


        response = JSON.stringify(response);

        $.ajax({
            cache: true,
            type: "POST",
            url: "/jz-jinzhuan-module-content/updateModuleContentById",
            data: response,// 你的formid
            async: false,
            headers: {
                'Content-Type':'application/json;charset=UTF-8'
            },
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });

    }

})
